<template>
  <div>
    <div class="banner">
      <div class="mask"></div>
      <div class="pic">
        <div class="cloud"></div>
      </div>
      <br />
      <p class="date">
        更新日期：{{ updataMonth > 9 ? updataMonth : "0" + updataMonth }}月{{
          updataDay > 9 ? updataDay : "0" + updataDay
        }}日
      </p>
    </div>
    <!-- 榜单列表 -->
    <div>
      <div
        v-for="(item, index) in hotSongList"
        :key="index"
        class="hotsonglist"
        @click="play(item.id)"
      >
        <span :class="['rank', { isred: index < 3 }]">{{
          Number(index + 1) > 9 ? Number(index + 1) : "0" + Number(index + 1)
        }}</span>

        <p>{{ item.name }}</p>
        <p class="artists">
          <i class="sq"></i>
          <span v-for="(artist, idx) in item.ar" :key="'artist' + idx">
            {{ artist.name }}
            <!-- 歌手是多人时，添加分割线 -->
            <span v-if="item.ar.length > 1 && idx != item.ar.length - 1"
              >/</span
            >
          </span>
        </p>
        <span class="play"></span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      updataTime: "",
      updataMonth: "",
      updataDay: "",
      hotSongList: [],
    };
  },
  created() {
    this.getTime();
    this.getHotSong();
  },
  methods: {
    getTime() {
      this.$http("/top/list?idx=1")
        .then((res) => {
          this.updataTime = res.data.playlist.updateTime;
          let updataDate = new Date(this.updataTime);
          this.updataMonth = updataDate.getMonth() + 1;
          this.updataDay = updataDate.getDate();
        })
        .catch((err) => {
          console.log(err);
        });
    },
    getHotSong() {
      this.$http("/top/list?idx=1")
        .then((res) => {
          this.hotSongList = res.data.playlist.tracks;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 跳转到播放页面
    play(id) {
      this.$router.push("/play/" + id);
    },
  },
};
</script>



<style scoped>
.banner {
  height: 186px;
  overflow: hidden;
  position: relative;
}
.mask {
  position: absolute;
  z-index: -1;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background-image: url("http://p1.music.126.net/GhhuF6Ep5Tq9IEvLsyCN7w==/18708190348409091.jpg");
  background-repeat: no-repeat;
  background-size: cover !important;
  background-position: 50%;
  filter: blur(20px);
  transform: scale(1.5);
}
.banner .pic {
  top: 25%;
  bottom: 0;
  z-index: 2;
  padding-left: 20px;
  box-sizing: border-box;
  position: relative;
}
.cloud {
  width: 168px;
  height: 78px;
  background: url(/static/img/index_icon_2x.png) no-repeat;
  background-position: -28px -33px;
  background-size: 168px 112px;
}
.date {
  margin-top: 50px;
  margin-left: 20px;
  color: #fff;
}
.hotsonglist {
  height: 76px;
  border-bottom: 1px solid #f4f4f4;
  font-size: 18px;
  padding-left: 40px;
  position: relative;
}
.artists {
  color: #666;
  font-size: 14px;
}
.sq {
  display: inline-block;
  width: 14px;
  height: 10px;
  background-image: url("../../static/img/index_icon_2x.png");
  background-position: 0 0;
  background-size: 190px 113px;
}
.rank {
  position: absolute;
  top: 0;
  left: 8px;
  font-size: 18px;
  line-height: 63px;
}
.isred {
  color: #f00;
}
.play {
  width: 45px;
  height: 45px;
  background-image: url(/static/img/index_icon_2x.5207a28.png);
  background-repeat: no-repeat;
  background-position: -47px 1px;
  position: absolute;
  right: 30px;
  top: 6px;
}
</style>